package com.example.second_home_work
import android.os.Bundle
import android.util.TypedValue
import android.widget.LinearLayout
import android.widget.Button
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    val expert = ProgramAdviser()
    //    在控制器上用上ProgramExpert这个类
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets}
        val button = findViewById<Button>(R.id.button)
        val spinner = findViewById<Spinner>(R.id.spinner)
        val textView = findViewById<TextView>(R.id.textView)
        button.setOnClickListener{
//                val selectedFeature = spinner.selectedItem.toString()
            textView.text = expert.Getlanguage(spinner.selectedItem.toString())
        }
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30f)
        val linearLayout: LinearLayout = findViewById(R.id.linearLayout2)
        val addTextViewButton: Button = findViewById(R.id.button2)

        addTextViewButton.setOnClickListener {
            addTextView(linearLayout)
        }
    }

    private fun addTextView(linearLayout: LinearLayout) {
        val textView = TextView(this).apply {
            // 设置 TextView 的属性
            text = "This is a new textView: ${linearLayout.childCount + 1}"
            textSize = 30f
            layoutParams = LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
            )
        }
        // 将 TextView 添加到 LinearLayout 容器中
        linearLayout.addView(textView)

//        设置字体大小
    }
}